﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using community.LanFen;

namespace community
{
    public partial class hypertension : Form
    {
        string strSql,strSql1;
        sql_database sd = new sql_database();
        SqlConnection conn;
        resident rd = new resident();
        int hyXLH=0;
        string oldhyname;
       

        public hypertension(int i)
        {
            InitializeComponent();
        }
        protected override bool ProcessDialogKey(Keys keyData)//按enter键时，光标跳到下一个控件输入
        {
            if (keyData == Keys.Enter)//&& !(ActiveControl is Button))
            {//碰到Button时不跳转到下一个控件，而是执行Button的单击事件
                keyData = Keys.Tab;
            }
            return base.ProcessDialogKey(keyData);
        }

        private void hynew_Click(object sender, EventArgs e)
        {

            residentcheck rchk = new residentcheck();
           

            if (rchk.ShowDialog(this) == DialogResult.OK)
            {
                if (residentcode.rescode != "")
                {
                    int i_XLH = 10000;//初始化高血压的序列号
                    string str = "select max(SEQID_INT) from T_CS_HYPERTENSIONVISITRECORD "; 
                    conn = new SqlConnection(SQL.conStr);
                    conn.Open();
                    SqlCommand cm = new SqlCommand(str, conn);
                    string str_XLH = Convert.ToString(cm.ExecuteScalar());
                    if (str_XLH == "") hyXLH = i_XLH;
                    hyXLH = Convert.ToInt32(str_XLH) + 1;
                    residentcode.hyperXLH = 0;
                   

                    strSql = "select residentname_chr , inhabitantcode_chr ,identitycard_chr ,";
                    strSql += "sex_chr,birth_dat,communityname_chr,phone_chr ,";
                    strSql += "addressprovince_vchr,addresscity_vchr ,addresscounty_vchr ,";
                    strSql += "addressvillage_vchr ,addresshamlet_vchr ,addressdoorplate_vchr,DATEDIFF(YYYY, birth_dat, getdate()) as age";
                    strSql +="  from t_cs_inhabitantrecord_new where inhabitantcode_chr ='" ;         
                    strSql += residentcode.rescode + "'";
 
                     
                    SqlCommand sqlcom = new SqlCommand(strSql, conn);

                    try
                    {
                        SqlDataReader rdr = sqlcom.ExecuteReader();

                        while (rdr.Read())
                        {

                            rname.Text = rdr["residentname_chr"].ToString();
                            rcode.Text = rdr["inhabitantcode_chr"].ToString();
                            rid.Text = rdr["identitycard_chr"].ToString();
                            rsex.Text = rdr["sex_chr"].ToString();
                            if (rdr["birth_dat"]!=DBNull .Value )  rbirth.Value = Convert.ToDateTime(rdr["birth_dat"]);
                            rcom.Text = rdr["communityname_chr"].ToString();
                            rphone.Text = rdr["phone_chr"].ToString();
                            rage.Text = rdr["age"].ToString();
                            string s1 = rdr["addressprovince_vchr"].ToString();//省
                            string s2 = rdr["addresscity_vchr"].ToString();//市
                            string s3 = rdr["addresscounty_vchr"].ToString();//县
                            string s4 = rdr["addressvillage_vchr"].ToString();//乡
                            string s5 = rdr["addresshamlet_vchr"].ToString();//村
                            string s6 = rdr["addressdoorplate_vchr"].ToString();//号
                            rad.Text = s1 + s2 + s3 + s4 + s5 + s6;
                           

                        }

                        rdr.Close();
                    } 
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                  
                   if(rcode.Text !="")
                   {
                   strSql= "select diseasename_vchr,happendate_dat ,suretime_dat ,diagnosehospital_vchr ,";
                   strSql += "surereason_chr ,healment_chr,healeffect_vchr ,remark_vchr";
                   strSql+= "  from  t_cs_membermedical  where inhabitantcode_chr ='" ;
                   strSql+= rcode .Text .Trim () + "'" + "  and  diseasename_vchr like  '%高血压%'";
                   //MessageBox.Show(strSql);
              
                   SqlCommand  sqlcom1= new SqlCommand(strSql, conn);
                                                          
                   try 
                   {
                       SqlDataReader rdr = sqlcom1.ExecuteReader();

                       if (rdr.Read()) //if (rdr != null && rdr.HasRows && rdr.Read()) 
                       {

                           hyname.Text = rdr["diseasename_vchr"].ToString();
                           if (rdr["happendate_dat"] != DBNull.Value) hytime.Value = Convert.ToDateTime(rdr["happendate_dat"]);
                           if (rdr["suretime_dat"] != DBNull.Value) hysuretime.Value = Convert.ToDateTime(rdr["suretime_dat"]);
                           hysurehospital.Text = rdr["diagnosehospital_vchr"].ToString();

                           hyreason.Text = rdr["surereason_chr"].ToString();
                           hyhealment.Text = rdr["healment_chr"].ToString();
                           hyhealeffect.Text = rdr["healeffect_vchr"].ToString();
                           hyremark.Text = rdr["remark_vchr"].ToString();
                           oldhyname = rdr["diseasename_vchr"].ToString();
                           hyname.ReadOnly = true;

                       }
                       else
                       {
                           hytime.Value = DateTime.Now;
                           hysuretime.Value = DateTime.Now;
                           hysurehospital.Text = "";
                           hyreason.Text = "";
                           hyhealment.Text = "";
                           hyhealeffect.Text = "";
                           hyremark.Text = ""; 
                           oldhyname = "";
                           hyname.Text = "高血压";
                           hyname.ReadOnly = true;
                           MessageBox.Show("请完善高血压信息");
                       }
                       rdr.Close();
 
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }

                    conn.Close();
                    
                    
                   }
                   residentcode.rescode = rcode.Text;
                   timehistory .Text= "";
                   
                }
            
            }
        }

         
        private void hysave_Click(object sender, EventArgs e)
        {
           
            
            //随访方式
            string str1 = radmz .Text;
            if (radmz.Checked) str1 = radmz .Text ;
            if (radjt.Checked) str1 = radjt.Text;
            if (raddh.Checked) str1 = raddh .Text;

            //获取症状
            string sym = "";
            foreach (Control check in this.panel2.Controls)
            {
                if (check is CheckBox)
                {
                    CheckBox cb = (CheckBox)check;
                    if (cb.Checked)
                    {
                        sym = cb.Text + ", " + sym;
                    }
                }
            }
            //MessageBox.Show(sym);
            //是否过敏
            string str2 = radadrsno .Text;
            if (radadrsno.Checked) str2 = radadrsno .Text ;
            if (radadrsyes.Checked) str2 = radadrsyes.Text;
             

            //是否转诊
            string str3 = radchangeno.Text;
            if (radchangeno.Checked) str3 = radchangeno .Text ;
            if (radchangeyes.Checked) str3 = radchangeyes.Text;
             

            if (rcode.Text.Trim() == "")
            {
                MessageBox.Show("请点击新增选择居民");

            }
            else 
            {
                if (hyname.Text.Trim() == "")
                    MessageBox.Show("请输入慢病名称");
                else
                {
                    if (vdoc.Text == "")
                        MessageBox.Show("请随访医生签名！");
                    else
                    {
                        strSql = "insert into T_CS_HYPERTENSIONVISITRECORD (SEQID_INT,INHABITANTCODE_CHR,RECORDDATE_DAT,";
                        strSql += "VISITTYPE_CHR,HYPERTENSIONSYMPTOM_CHR,HYPERTENSIONSYMPTOM_VCHR,SIGN_BLUTDRUCK_INT,SIGN_WEIGHT_INT,";
                        strSql += "TALL_INT,SIGN_HEARTRATE_INT,SIGN_PULSTAR_INT,SIGN_BREATHE_INT,SIGN_OTHER_VCHR,SMOKING_INT,";
                        strSql += "DRINKING_INT,SPORTS_WEEK_INT,SPORTS_MINUTE_INT,SALT_INT,MENTALADJUSTMENT_CHR,FOLLOWDOC_CHR,";
                        strSql += "ASSISTCHECK_VHCR,TAKEMEDICINE_CHR,DRUGADRS_CHR,ADRSSYMPTOM_CHR,VISITCLASSIFY_CHR,REFERRALS_CHR,";
                        strSql += "REFERRALSREASON_VCHR,REFERRALSORGANIZ_VCHR,FOLLOWUPIDEA_VCHR,NEXTRECORDATE_DAT,RECORDDOCNAME_VCHR,";
                        strSql += "FAMILIESSIGNATURE_VCHR,INPUTER_CHR) values ('";
                        strSql += residentcode .hyperXLH  + "','" + rcode.Text.Trim() + "','" + visittime.Text + "','" + str1 + "','" + sym + "','";
                        strSql += othersign.Text.Trim() + "','" + druck.Text.Trim() + "','" + weight.Text.Trim() + "','";
                        strSql += tall.Text.Trim() + "','" + heartrate.Text.Trim() + "','" + pulstar.Text.Trim() + "','";
                        strSql += breathe.Text.Trim() + "','" + othersign.Text.Trim() + "','" + smoke.Text.Trim() + "','";
                        strSql += drink.Text.Trim() + "','" + sportweek.Text.Trim() + "','" + sportmin.Text.Trim() + "','";
                        strSql += saltin.Text.Trim() + "','" + memtal.Text.Trim() + "','" + follow.Text.Trim() + "','";
                        strSql += assistant.Text.Trim() + "','" + take.Text.Trim() + "','" + str2 + "','" + adrssymptom.Text.Trim() + "','";
                        strSql += classify.Text.Trim() + "','" + str3 + "','" + changereason.Text.Trim() + "','";
                        strSql += changeunit.Text.Trim() + "','" + visitidea.Text.Trim() + "','" + nexttime.Text + "','";
                        strSql += vdoc.Text.Trim() + "','" + vres.Text.Trim() + "','" + hyin.Text.Trim() + "')";
                        rd.new_row(strSql);
                        residentcode.hyperXLH = hyXLH;
                        usedrug.Enabled = true;
                      
                        if (oldhyname=="" )
                        {
                            strSql = "insert into t_cs_membermedical (inhabitantcode_chr,diseasename_vchr ,happendate_dat ,suretime_dat ,diagnosehospital_vchr ,surereason_chr ,healment_chr ,healeffect_vchr ,remark_vchr) values (  '";
                            strSql += rcode.Text.Trim() + "','" + hyname.Text.Trim() + "','" + hytime.Text  + "','" + hysuretime.Text + "','" + hysurehospital.Text.Trim() + "','" + hyreason.Text.Trim() + "','" + hyhealment.Text.Trim() + "','" + hyhealeffect.Text.Trim() + "','" + hyremark.Text.Trim() + "')";
                            rd.new_row(strSql);
                            MessageBox.Show("随访信息和疾病信息已保存");
                        }
                        
                         else MessageBox.Show("随访信息已保存");
                        }
                    

                    }

                }
            

        }

        private void hypertension_Load(object sender, EventArgs e)
        {
            showindoc.Visible = false;
            showhydoc.Visible = false;
            showvisitime.Visible = false;
            radmz.Checked = true;
            radadrsno.Checked = true;
            radchangeno.Checked = true;
            usedrug.Enabled = false;
            if (checkqt.Checked) othersym.ReadOnly = false;
            else othersym.ReadOnly = true;
            timehistory.Text = Convert.ToString(DateTime.Now);
            
           
        }
        private void druguse()
        {
            strSql = "select SEQDRUGID_INT as 序列号,DRUGNAME_VCHR as 药物名称 ,DRUPFREQUENCY_VCHR as 使用频率,";
            strSql += "DRUPDOSEUNIT_VCHR as 剂量单位,DRUGDOSEONES_VCHR as  一次剂量,DRUGDOSETOTAL_VHCR as 总剂量,";
            strSql += "DRUGUSEAGE_VCHR as 用法,DRUGREACTIONS_INT as 是否副作用,DRUGREACTIONS_VCHR as 副作用,";
            strSql += "DRUGDATE_VCHR as 用药时间  from T_CS_HYPERTENSIONRECORD_DRUG where INHABITANTCODE_CHR='" +rcode .Text+ "'";
            strSql += "  and  SEQID_INT='" + residentcode.hyperXLH + "'";
            sd.show_dataGridview(strSql, "T_CS_HYPERTENSIONRECORD_DRUG", drugsituation);
        }

        private void usedrug_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //residentcode.hyperXLH = hyXLH;
           
            usedrug ud = new usedrug(this);
            if (ud.ShowDialog(this) == DialogResult.OK)
            {
                druguse();
            }

        }

        private void radadrsyes_CheckedChanged(object sender, EventArgs e)
        {

            adrssymptom.ReadOnly = false;
        }

        private void radchangeyes_CheckedChanged(object sender, EventArgs e)
        {
            changereason.ReadOnly = false;
            changeunit.ReadOnly = false;
        }

        private void radadrsno_CheckedChanged(object sender, EventArgs e)
        {
            adrssymptom.ReadOnly = true;
        }

        private void radchangeno_CheckedChanged(object sender, EventArgs e)
        {
            changereason.ReadOnly = true ;
            changeunit.ReadOnly = true ;
        }

        private void changehy_Click(object sender, EventArgs e)
        {

        }

        private void checkqt_CheckedChanged(object sender, EventArgs e)
        {
            othersym .ReadOnly  = false;
        }

        

        private void showvisitime_CellClick(object sender, DataGridViewCellEventArgs e)
        {
           if (e.RowIndex >=0)
           {
                 
                 timehistory .Text =showvisitime .Rows [e.RowIndex ].Cells [0].Value .ToString ();
                 showvisitime.Visible = false;
                 if (showvisitime.Rows[e.RowIndex].Cells[0].Value !=null)
                 {
                     
                     strSql = "select SEQID_INT,RECORDDATE_DAT,VISITTYPE_CHR,HYPERTENSIONSYMPTOM_CHR,HYPERTENSIONSYMPTOM_VCHR,SIGN_BLUTDRUCK_INT,SIGN_WEIGHT_INT,";
                     strSql += "TALL_INT,SIGN_HEARTRATE_INT,SIGN_PULSTAR_INT,SIGN_BREATHE_INT,SIGN_OTHER_VCHR,SMOKING_INT,";
                     strSql += "DRINKING_INT,SPORTS_WEEK_INT,SPORTS_MINUTE_INT,SALT_INT,MENTALADJUSTMENT_CHR,FOLLOWDOC_CHR,";
                     strSql += "ASSISTCHECK_VHCR,TAKEMEDICINE_CHR,DRUGADRS_CHR,ADRSSYMPTOM_CHR,VISITCLASSIFY_CHR,REFERRALS_CHR,";
                     strSql += "REFERRALSREASON_VCHR,REFERRALSORGANIZ_VCHR,FOLLOWUPIDEA_VCHR,NEXTRECORDATE_DAT,RECORDDOCNAME_VCHR,";
                     strSql += "FAMILIESSIGNATURE_VCHR,INPUTER_CHR from T_CS_HYPERTENSIONVISITRECORD  where INHABITANTCODE_CHR='";
                     strSql += rcode.Text.Trim() + "'  and  RECORDDATE_DAT='" + Convert.ToDateTime(timehistory.Text) + "'";
                     conn = new SqlConnection(SQL.conStr);
                     conn.Open();
                     SqlCommand sqlcom = new SqlCommand(strSql, conn);

                     try
                     {
                         SqlDataReader rdr = sqlcom.ExecuteReader();

                         if (rdr.Read())
                         {

                             if (rdr["RECORDDATE_DAT"] != DBNull.Value) visittime.Value = Convert.ToDateTime(rdr["RECORDDATE_DAT"]);
                             string type = rdr["VISITTYPE_CHR"].ToString();

                             //获取随访方式
                             if (type.Trim() == radmz.Text.Trim()) radmz.Checked = true;
                             if (type.Trim() == radjt.Text.Trim()) radjt.Checked = true;
                             if (type.Trim() == raddh.Text.Trim()) raddh.Checked = true;

                             //获取症状
                             string sym = rdr["HYPERTENSIONSYMPTOM_CHR"].ToString();
                             foreach (Control check in this.panel2.Controls)
                             {
                                 if (check is CheckBox)
                                 {
                                     CheckBox cb = (CheckBox)check;
                                     if (sym.Contains(cb.Text.Trim())) cb.Checked = true;
                                     
                                 }
                             }
                             othersym.Text = rdr["HYPERTENSIONSYMPTOM_VCHR"].ToString();
                             druck.Text = rdr["SIGN_BLUTDRUCK_INT"].ToString();
                             weight.Text = rdr["SIGN_WEIGHT_INT"].ToString();
                             tall.Text = rdr["TALL_INT"].ToString();
                             heartrate.Text = rdr["SIGN_HEARTRATE_INT"].ToString();
                             pulstar.Text = rdr["SIGN_PULSTAR_INT"].ToString();
                             breathe.Text = rdr["SIGN_BREATHE_INT"].ToString();
                             othersign.Text = rdr["SIGN_OTHER_VCHR"].ToString();
                             smoke.Text = rdr["SMOKING_INT"].ToString();
                             drink.Text = rdr["DRINKING_INT"].ToString();
                             sportweek.Text = rdr["SPORTS_WEEK_INT"].ToString();
                             sportmin.Text = rdr["SPORTS_MINUTE_INT"].ToString();
                             saltin.Text = rdr["SALT_INT"].ToString();
                             memtal.Text = rdr["MENTALADJUSTMENT_CHR"].ToString();
                             follow.Text = rdr["FOLLOWDOC_CHR"].ToString();
                             assistant.Text = rdr["ASSISTCHECK_VHCR"].ToString();
                             take.Text = rdr["TAKEMEDICINE_CHR"].ToString();
                             string st2 = rdr["DRUGADRS_CHR"].ToString();
                             if (st2.Trim() == radadrsno.Text.Trim()) radadrsno.Checked = true;
                             if (st2.Trim() == radadrsyes.Text.Trim()) radadrsyes.Checked = true;

                             adrssymptom.Text = rdr["ADRSSYMPTOM_CHR"].ToString();
                             classify.Text = rdr["VISITCLASSIFY_CHR"].ToString();

                             string st3 = rdr["REFERRALS_CHR"].ToString();
                             if (st3.Trim() == radchangeno.Text.Trim()) radchangeno.Checked = true;
                             if (st3.Trim() == radchangeyes.Text.Trim()) radchangeyes.Checked = true;

                             changereason.Text = rdr["REFERRALSREASON_VCHR"].ToString();
                             changeunit.Text = rdr["REFERRALSORGANIZ_VCHR"].ToString();
                             visitidea.Text = rdr["FOLLOWUPIDEA_VCHR"].ToString();
                             if (rdr["NEXTRECORDATE_DAT"] != DBNull.Value) nexttime.Value = Convert.ToDateTime(rdr["NEXTRECORDATE_DAT"]);
                             vdoc.Text = rdr["RECORDDOCNAME_VCHR"].ToString();
                             vres.Text = rdr["FAMILIESSIGNATURE_VCHR"].ToString();
                             hyin.Text = rdr["INPUTER_CHR"].ToString();
                             residentcode.hyperXLH = Convert.ToInt32(rdr["SEQID_INT"]);
                             usedrug.Enabled = true;
                             druguse();
                         }
                         else residentcode.hyperXLH = 0;
                         rdr.Close();
                         conn.Close();
                          
                     }
                     catch (Exception ex)
                     {
                         MessageBox.Show(ex.ToString());
                     }
                     
                 }
               
           }
        }

        private void timehistory_Click(object sender, EventArgs e)
        {
            if (rcode.Text.Trim() != "")
            {

                strSql = "select  RECORDDATE_DAT from T_CS_HYPERTENSIONVISITRECORD where INHABITANTCODE_CHR='";
                strSql += rcode.Text.Trim()+"'";
                sd.show_dataGridview(strSql, "T_CS_HYPERTENSIONVISITRECORD", showvisitime);
                showvisitime.Visible = true;
              
                
            }
            else MessageBox.Show("请点击新增选择居民");
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            
            //随访方式
            string str1 = radmz .Text;
            if (radmz.Checked) str1 = radmz .Text ;
            if (radjt.Checked) str1 = radjt.Text;
            if (raddh.Checked) str1 = raddh .Text;

            //获取症状
            string sym = "";
            foreach (Control check in this.panel2.Controls)
            {
                if (check is CheckBox)
                {
                    CheckBox cb = (CheckBox)check;
                    if (cb.Checked)
                    {
                        sym = cb.Text + ", " + sym;
                    }
                }
            }
           // MessageBox.Show(sym);
            //是否过敏
            string str2 = radadrsno .Text;
            if (radadrsno.Checked) str2 = radadrsno .Text ;
            if (radadrsyes.Checked) str2 = radadrsyes.Text;
             

            //是否转诊
            string str3 = radchangeno.Text;
            if (radchangeno.Checked) str3 = radchangeno .Text ;
            if (radchangeyes.Checked) str3 = radchangeyes.Text;
            if (rcode.Text == "")
                MessageBox.Show("请按新增选择居民");
            else
            {
                if (timehistory .Text== "")
                    MessageBox.Show("请双击选择随访时间");
                else
                {
                     
                        strSql = "update T_CS_HYPERTENSIONVISITRECORD set   RECORDDATE_DAT='" + visittime.Text + "',VISITTYPE_CHR='";
                        strSql += str1 + "',HYPERTENSIONSYMPTOM_CHR='" + sym + "',HYPERTENSIONSYMPTOM_VCHR='" + othersign.Text.Trim() + "',SIGN_BLUTDRUCK_INT='";
                        strSql += druck.Text.Trim() + "',SIGN_WEIGHT_INT='" + weight.Text.Trim() + "',TALL_INT='" + tall.Text.Trim() + "',SIGN_HEARTRATE_INT='";
                        strSql += heartrate.Text.Trim() + "',SIGN_PULSTAR_INT='" + pulstar.Text.Trim() + "',SIGN_BREATHE_INT='";
                        strSql += breathe.Text.Trim() + "',SIGN_OTHER_VCHR='" + othersign.Text.Trim() + "',SMOKING_INT='" + smoke.Text.Trim() + "',DRINKING_INT='";
                        strSql += drink.Text.Trim() + "',SPORTS_WEEK_INT='" + sportweek.Text.Trim() + "',SPORTS_MINUTE_INT='" + sportmin.Text.Trim() + "',SALT_INT='";
                        strSql += saltin.Text.Trim() + "',MENTALADJUSTMENT_CHR='" + memtal.Text.Trim() + "',FOLLOWDOC_CHR='" + follow.Text.Trim() + "',ASSISTCHECK_VHCR='";
                        strSql += assistant.Text.Trim() + "',TAKEMEDICINE_CHR='" + take.Text.Trim() + "',DRUGADRS_CHR='" + str2 + "',ADRSSYMPTOM_CHR='";
                        strSql += adrssymptom.Text.Trim() + "',VISITCLASSIFY_CHR='" + classify.Text.Trim() + "',REFERRALS_CHR='" + str3 + "',REFERRALSREASON_VCHR='";
                        strSql += changereason.Text.Trim() + "',REFERRALSORGANIZ_VCHR='" + changeunit.Text.Trim() + "',FOLLOWUPIDEA_VCHR='";
                        strSql += visitidea.Text.Trim() + "',NEXTRECORDATE_DAT='" + nexttime.Text + "',RECORDDOCNAME_VCHR='" + vdoc.Text.Trim() + "',FAMILIESSIGNATURE_VCHR='";
                        strSql += vres.Text.Trim() + "',INPUTER_CHR='" + hyin.Text.Trim() + "'  where SEQID_INT='" + residentcode .hyperXLH+ "' and  INHABITANTCODE_CHR='" + rcode.Text.Trim() + "'";
                        conn = new SqlConnection(SQL.conStr);
                        conn.Open();
                        SqlCommand sqlcmd = new SqlCommand(strSql, conn);

                        DialogResult jieguo = MessageBox.Show("您确认保存修改?", "修改提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (jieguo == DialogResult.OK)
                        {
                            try
                            {
                                int i = sqlcmd.ExecuteNonQuery();
                                if (i == 1)
                                    MessageBox.Show("修改保存成功");
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                        }
                        else
                            MessageBox.Show("您已取消保存修改");
                        conn.Close();


                    }
                

            }
            
             
        }

        private void changedisease_Click(object sender, EventArgs e)
        {
            if (oldhyname != "")
            {
                DialogResult jieguo = MessageBox.Show("确认要保存修改的疾病信息？", "更新提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (jieguo == DialogResult.OK)
                {
                    strSql = "update t_cs_membermedical  set  inhabitantcode_chr='" + rcode.Text.Trim() + "'";
                    strSql += ",happendate_dat='" + hytime.Text + "',suretime_dat='";
                    strSql += hysuretime.Text + "', diagnosehospital_vchr='" + hysurehospital.Text.Trim() + "',surereason_chr ='";
                    strSql += hyreason.Text.Trim() + "',healment_chr='" + hyhealment.Text.Trim() + "',healeffect_vchr='";
                    strSql += hyhealeffect.Text.Trim() + "',remark_vchr='" + hyremark.Text.Trim() + "'";
                    strSql += " where inhabitantcode_chr='" + rcode.Text.Trim() + "'  and diseasename_vchr='";
                    strSql += oldhyname + "'";
                    rd.new_row(strSql);
                    MessageBox.Show("疾病更新信息已保存");
                }
            }
            else MessageBox.Show("没有要修改的信息");
                          
        }

        private void timehistory_TextChanged(object sender, EventArgs e)
        {
            if (timehistory.Text == "")
                usedrug.Enabled = false;
        }

        private void vdoc_Click(object sender, EventArgs e)
        {
            string strSql = "select empid_chr as 职工编号, lastname_vchr as 职工姓名 from T_BSE_EMPLOYEE";
            sd.show_dataGridview(strSql, "T_BSE_EMPLOYEE",showhydoc);
            showhydoc.Visible = true;
        }

        private void showhydoc_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                 vdoc .Text = showhydoc.Rows[e.RowIndex].Cells[1].Value.ToString();

                 if (vdoc != null) showhydoc.Visible = false;
            }
        }

        private void hyin_Click(object sender, EventArgs e)
        {
            string strSql= "select empid_chr as 职工编号, lastname_vchr as 职工姓名 from T_BSE_EMPLOYEE";
            sd.show_dataGridview(strSql, "T_BSE_EMPLOYEE",showindoc);
            showindoc.Visible = true;
        }

        private void showindoc_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                hyin .Text  = showindoc .Rows[e.RowIndex].Cells[1].Value.ToString();

                if (hyin  != null) showindoc.Visible = false;
            }
        }

        private void 删除toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (rcode.Text.Trim() == "")
                MessageBox.Show("请点击新增选择居民");
            else
            {
                if (timehistory.Text == "")
                    MessageBox.Show("请选择随访时间");
                else
                {
                    strSql1 = "delete from T_CS_HYPERTENSIONRECORD_DRUG  where INHABITANTCODE_CHR='" + rcode.Text.Trim() + "'";
                    strSql1 += "  and SEQID_INT='" + residentcode.hyperXLH + "'";
                    strSql = "delete from T_CS_HYPERTENSIONVISITRECORD  where INHABITANTCODE_CHR='" + rcode.Text.Trim() + "'";
                    strSql += "  and SEQID_INT='" + residentcode.hyperXLH + "'";

                    conn = new SqlConnection(SQL.conStr);
                    conn.Open();
                    SqlCommand sqlcmd1 = new SqlCommand(strSql1, conn);
                    SqlCommand sqlcmd = new SqlCommand(strSql, conn);
                    DialogResult jieguo = MessageBox.Show("确认要保存修改的疾病信息？", "更新提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    if (jieguo == DialogResult.OK)
                    {
                        try
                        {
                            int i1 = sqlcmd1.ExecuteNonQuery();
                            int i2 = sqlcmd.ExecuteNonQuery();
                            if (i1 == 1 && i2 == 1)
                                MessageBox.Show("随访记录和相关的随访用药信息删除成功");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    else MessageBox.Show("您已取消删除随访记录");
                }
            }

        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            hypertensionpatient hp = new hypertensionpatient();
            hp.Show();
        }

        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {
            hypertensionreport hpr = new hypertensionreport();
            hpr.Show();
        }

        

         
         
        

         
        
        
         
         

        
         
        
    }

         
}
